package Account

import (
	"Identity/common"
	"github.com/ethereum/go-ethereum/rlp"
	"golang.org/x/crypto/sha3"
)

//func SignLoveToken(token *LoveToken,prv *ecdsa.PrivateKey) (*TokenData,error){
//	digestHash := rlpHashTokenData(token)
//	signature  ,err := crypto.Sign(digestHash[:],prv)
//	if err != nil{
//		return nil ,err
//	}
//
//	cpy :=&LoveToken{data:token.data}
//	cpy.data.DigestHash= digestHash
//	cpy.aSigned = signature
//}
//
//func VerfifySig(digestHash []byte,pubkey []byte ,signature []byte ){
//
//}
func rlpHashTokenData(token *LoveToken) common.Hash{
	return rlpHash([]interface{}{
		token.data.Msg,
		token.data.AAddress,
		token.data.BAddress,
		token.data.StartTime,
		token.data.Endtime,
	})

}

func rlpHashLoveToken(lovetoken * LoveToken)common.Hash{
	return rlpHash([]interface{}{
		lovetoken.getDigestHash(),
		lovetoken.data.aSigned,
		lovetoken.data.bSigned,
	})
}


func rlpHash(x interface{}) (h common.Hash) {
	hw := sha3.NewLegacyKeccak256()
	rlp.Encode(hw, x)
	hw.Sum(h[:0])
	return h
}